home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / vsc92nov.zip / Cont.h < prev    next >
C/C++ Source or Header  |  1992-11-02  |  3KB  |  88 lines

  1. /*
  2.  * Cont.h -- Declarations for Scheme Continuations
  3.  *
  4.  * (C) m.b (Matthias Blume), Apr 1992, HUB/Ger
  5.  *
  6.  * ident "@(#) Cont.h (C) M.Blume, Humboldt-Uni Berlin, 1.3"
  7.  */
  8.  
  9. # ifndef CONT_H_
  10. # define CONT_H_
  11.  
  12. # include "storage.h"
  13. # include "Vector.h"
  14. # include "Code.h"
  15.  
  16. /*
  17.  * A Continuation (activation record) will be established during a ``call''.
  18.  * After return of the call there may be the result on the stack or
  19.  * another ``call'' has to be carried out.
  20.  * The latter case is signalled by setting call_again to the count
  21.  * of items on the stack, i.e. the number of arguments + one (the function
  22.  * to call). If the plain result is available then call_again == 0.
  23.  */
  24. typedef
  25. struct ScmContinuation {
  26.   object_head _;
  27.   struct ScmContinuation *father;
  28.   ScmCode *code;        /* This is NULL for C-Continuations */
  29.   unsigned long nxt_stat;    /* This is either the pc of a byte-cont.
  30.                    or the argument for GetScmPrimitive */
  31.   void *environ;        /* either a vector (Byte) or anything (C) */
  32.   ScmVector *constants;        /* a copy of code's constants or NULL */
  33.   ScmVector *stack;        /* this is the stack */
  34.   unsigned short stack_top;    /* stack_length is part of stack (vector) */
  35.   short int shared;        /* this record is shared (call/cc) */
  36.   unsigned short call_again;
  37. } ScmContinuation;
  38.  
  39. extern od_vector ScmContinuation_od_vector;
  40. # define ScmContinuation_description (ScmContinuation_od_vector[0])
  41.  
  42. # ifdef CONT_STACK_FUNCTIONS
  43.  
  44.   extern void ScmCPush (ScmContinuation *cont, void *item);
  45.   extern void *ScmCPop (ScmContinuation *cont);
  46.   extern void ScmCSetTop (ScmContinuation *cont, void *item);
  47.   extern void *ScmCPeek (ScmContinuation *cont);
  48.   extern void ScmPush (void *item);
  49.   extern void *ScmPop (void);
  50.   extern void ScmSetTop (void *item);
  51.   extern void *ScmPeek (void);
  52.  
  53. # else
  54.  
  55.   extern void intern_ScmCPush (ScmContinuation *cont, void *item);
  56.  
  57. #   define ScmCPush(c,x)    \
  58.     ((c)->stack_top>=(c)->stack->length \
  59.         ?(void)intern_ScmCPush((c),(x)) \
  60.         :(void)((c)->stack->array[(c)->stack_top++]=(x)))
  61. #   define ScmCPop(c) ((c)->stack->array[--(c)->stack_top])
  62. #   define ScmCSetTop(c,x) ((void)((c)->stack->array[(c)->stack_top-1]=(x)))
  63. #   define ScmCPeek(c) ((c)->stack->array[(c)->stack_top-1])
  64.  
  65.   extern void intern_ScmPush (void *item);
  66.  
  67. #   define ScmPush(x)    \
  68.     (ScmCC.stack_top>=ScmCC.stack->length \
  69.         ?(void)intern_ScmPush(x) \
  70.         :(void)(ScmCC.stack->array[ScmCC.stack_top++]=(x)))
  71. #   define ScmPop() (ScmCC.stack->array[--ScmCC.stack_top])
  72. #   define ScmSetTop(x) ((void)(ScmCC.stack->array[ScmCC.stack_top-1]=(x)))
  73. #   define ScmPeek() (ScmCC.stack->array[ScmCC.stack_top-1])
  74.  
  75. # endif
  76.  
  77. extern void ScmPushContinuation (unsigned short stackreq);
  78. extern void ScmSetContinuation (ScmContinuation *);
  79. extern ScmContinuation *ScmGetContinuation (void);
  80. extern void ScmRevertToFatherContinuation (unsigned short stackcnt);
  81.  
  82. extern void *ScmMode (int mode);
  83. extern void ScmSetMode (int mode, void *item);
  84.  
  85. extern ScmContinuation ScmCC;    /* the CURRENT CONTINUATION */
  86.  
  87. # endif
  88.